<?php

namespace app\admin\controller;

use think\Db;
use think\Controller;
use \think\Request;

class Index extends \think\Controller
{

    public function _initialize()
    {
        $this->assign('LoginUserInfo', $this->LoginUserInfo);
        $this->assign('ruleLists', $this->LoginUserInfo['CurrPower']);
    }


    public function index()
    {


        $userInfo = $this->LoginUserInfo['UserInfo'];//当前登录用户信息
        $userModel = new \app\admin\model\User();

        $sys_opt = trim(input("request.sys_opt"));//auth
        if ($sys_opt) {


            $psw = trim(input("request.psw"));//auth

            if (empty($psw)) {
                $return = ['err' => 3, 'msg' => '对不起,新密码为空'];
                return json($return);
            }

            $w = array(
                'id' => $userInfo['id']
            );
            $update = array(
                'pwd' => UserPwdE($psw),


            );
            $res = $userModel->updateDataForWhere($update, $w);

            if ($res || ($res === 0)) {
                $return = ['err' => 0, 'msg' => '操作成功'];
                return json($return);
            } else {
                $return = ['err' => 3, 'msg' => '操作失败'];
                return json($return);
            }
        }

        //查询用户
        $info = $userModel->getDataForWhere(array('id' => $userInfo['id']));
        $this->assign('info', $info);

        //查询用户部门
        $depModel = new \app\admin\model\Dep();

        $tmpUserDepList = $depModel->getAll();//查询一级部门

        $userDepList = array();
        if ($tmpUserDepList) {
            foreach ($tmpUserDepList as $key => $val) {
                $userDepList[$val['id']] = $val;
            }
        }
        $this->assign('userDepList', $userDepList);

        //查询分组
        $groupList = array();
        $groupModel = new \app\admin\model\Group();
        $groupList = $groupModel->getGroupList();
        $this->assign('groupList', $groupList);

        $groupList_mk = array();
        foreach ($groupList as $k => $v) {
            $groupList_mk[$v['id']] = $v;
        }

        $this->assign('groupList_mk', $groupList_mk);

        //设置全局信息
        $title = "我的资料";
        $this->assign('title', $title);
        $this->assign('id', $id);
        return view('index');

    }

}